require 'rubygems'
require 'open-uri'

url = 'http://greatwords.ru/';
page = open(url);
text = page.read;
afile=File.new('dump.txt','w');
hrefs=text.scan(%r(<a href="(/author.*)" class.*">(.*)</a>))
threads=[]
Thread.abort_on_exception=false;
for list in hrefs
          threads << Thread.new(list){ |mylist|
          sleep(rand(0)/2000.0)
          #afile.puts mylist[0]
          trurl=url[0..-2]+mylist[0];
          trfile=File.new(mylist[1],'w');
          trpage=open(trurl);
          trtext=trpage.read;
          quteslist=trtext.scan(%r(<a href="(/quote.*)" onclick="d.*author-quote.*))
          #p qutes
          trtreads=[]
          for quolist in quteslist
            trtreads << Thread.new(quolist){|q|
              sleep(rand(0)/2000.0)
              trtrurl=url[0..-2]+q[0]
              trtrpage=open(trtrurl);
              trtrtext=trtrpage.read;
              quote=trtrtext.scan(%r(<p class="greatwords" id="quote-p">(.*)</p>))
              #quote=trtrtext.scan(%r(<p class="greatwords" id="quote-p">(.*)</p>))
              trfile.puts quote[0]
             }
          end
          trtreads.each{|a| a.join}
           }
end
threads.each{|t| t.join }




